import { OrderService } from './../src/service/orderService';
import { DataContextFactory } from '../src/domain/fbsDataContext';
import { TableGroup } from '../src/domain/model/tableGroup';
import { TableParty } from '../src/domain/model/tableParty';
import { Order } from '../src/domain/model/order';
import { Guid } from '../src/common/utils/guid';
import assert = require("assert");


describe("orderService", function () {
    let orderSvr: OrderService;
    before(function () {
        orderSvr = new OrderService();
    });

    describe("GetPreOrderByTableGroupId", () => {
        let tableGroup: TableGroup;
        let tbpList: TableParty[] = [];
        let preOrderList: Order[] = [];
        before(async () => {
            let ctx = DataContextFactory.GetDataContext();
            tableGroup = new TableGroup();
            tableGroup.id = Guid.GetGuid();

            for (let index = 0; index < 50; index++) {
                let tbp = new TableParty();
                tbp.id = Guid.GetGuid();
                tbp.tableGroupId = tableGroup.id;
                tbp.orderId = Guid.GetGuid();

                for (let i = 0; i < 10; i++) {
                    let preOrder = new Order();
                    preOrder.id = Guid.GetGuid();
                    preOrder.master = tbp.orderId;

                    await ctx.Create(preOrder);
                }

                await ctx.Create(tbp);
            }
        })
        it("根据台桌组获取preOrderList", async () => {
            let preOrderList = await orderSvr.GetPreOrderByTableGroupId(tableGroup.id);
            assert.notEqual(preOrderList, null, "preOrderList.length not be 0");
            for (let item of preOrderList) {
                assert.notEqual(item, undefined, "item must be undefined!");
                assert.notEqual(item.master, null, "不是preOrder类型");
            }
        })
    })
});